/**
 * 北京中流科技有限公司 版权所有
 * http://www.chinasoa.com.cn
 */
package cn.com.chinasoa.course.subscribe.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import cn.com.chinasoa.course.subscribe.model.ArrangedCourse;
import cn.com.chinasoa.course.subscribe.model.PrivilegeStrategy;
import cn.com.chinasoa.course.subscribe.model.TrainingAddress;
import cn.com.chinasoa.course.subscribe.model.TrainingSubject;

/**
 * @author 刘洋(liuyang@chinasoa.com.cn)
 * 2007-11-3下午07:43:46
 */
public class ModelEntityHelper {
	public static List<TrainingAddress> listTrainingAddress(){
		List<TrainingAddress> vTrainingAddressList = new ArrayList<TrainingAddress>();
		EntityManager em = EntityManagerHelper.getEntityManager();
		Query q = em.createQuery("select ta from TrainingAddress ta");
		List taList = q.getResultList();
		for(Iterator taIt = taList.iterator();taIt.hasNext();){
			Object taObj = taIt.next();
			if((taObj!=null)&&(taObj instanceof TrainingAddress)){
				vTrainingAddressList.add((TrainingAddress)taObj);
			}
		}
		EntityManagerHelper.closeEntityManager();
		return vTrainingAddressList;
	}
	
	public static List<TrainingSubject> listTrainingSubject(){
		List<TrainingSubject> vTrainingSubjectList = new ArrayList<TrainingSubject>();
		EntityManager em = EntityManagerHelper.getEntityManager();
		Query q = em.createQuery("select ts from TrainingSubject ts");
		List taList = q.getResultList();
		for(Iterator taIt = taList.iterator();taIt.hasNext();){
			Object taObj = taIt.next();
			if((taObj!=null)&&(taObj instanceof TrainingSubject)){
				vTrainingSubjectList.add((TrainingSubject)taObj);
			}
		}
		EntityManagerHelper.closeEntityManager();
		return vTrainingSubjectList;
	}

	public static List<PrivilegeStrategy> listPrivilegeStrategy(){
		List<PrivilegeStrategy> vPrivilegeStrategyList = new ArrayList<PrivilegeStrategy>();
		EntityManager em = EntityManagerHelper.getEntityManager();
		Query q = em.createQuery("select ps from PrivilegeStrategy ps");
		List taList = q.getResultList();
		for(Iterator psIt = taList.iterator();psIt.hasNext();){
			Object psObj = psIt.next();
			if((psObj!=null)&&(psObj instanceof PrivilegeStrategy)){
				vPrivilegeStrategyList.add((PrivilegeStrategy)psObj);
			}
		}
		EntityManagerHelper.closeEntityManager();
		return vPrivilegeStrategyList;
	}

	public static List<ArrangedCourse> listArrangedCourse(){
		List<ArrangedCourse> vArrangedCourseList = new ArrayList<ArrangedCourse>();
		EntityManager em = EntityManagerHelper.getEntityManager();
		Query q = em.createQuery("SELECT ac FROM ArrangedCourse ac");
		List acList = q.getResultList();
		for(Iterator acIt = acList.iterator();acIt.hasNext();){
			Object acObj = acIt.next();
			if((acObj!=null)&&(acObj instanceof ArrangedCourse)){
				vArrangedCourseList.add((ArrangedCourse)acObj);
			}
		}
		EntityManagerHelper.closeEntityManager();
		return vArrangedCourseList;
	}

}
